package org.komarichin.jdo.persistence;

import com.google.appengine.api.datastore.Text;
import org.komarichin.beans.IArticle;

import javax.jdo.annotations.*;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * &nbsp;
 * </p>
 * User: Michael Komarichin
 * Date: Jan 23, 2010
 * Time: 9:01:55 PM
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Article implements IArticle<Long> {

    private static final long serialVersionUID = -7667036969777806083L;

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    @Persistent
    private String name;
    @Persistent
    private String source;
    @Persistent
    private String title;
    @Persistent
    private String description;
    @Persistent
    private String keyWords;
    @Persistent
    private Date create;
    @Persistent
    private Date update;
    @Persistent
    private Text content;
    @Persistent
    private Long language = 0l;
    @Persistent
    @Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "create desc"))
    private List<Comment> comments;
    @NotPersistent
    private String link;


    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String getKeyWords() {
        return keyWords;
    }

    @Override
    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }

    @Override
    public Date getCreate() {
        return create;
    }

    @Override
    public void setCreate(Date create) {
        this.create = create;
        this.update = create;
    }


    @Override
    public void setUpdate() {
        this.update = new Date();
    }

    @Override
    public Date getUpdate() {
        return update;
    }

    @Override
    public void setUpdate(Date update) {
        this.update = update;
    }

    @Override
    public String getContent() {
        return content.getValue();
    }

    @Override
    public void setContent(String content) {
        this.content = new Text(content);
    }

    @Override
    public String getSource() {
        return source;
    }

    @Override
    public void setSource(String source) {
        this.source = source;
    }

    @Override
    public Long getLanguage() {
        return language;
    }

    @Override
    public void setLanguage(Long language) {
        this.language = language;
    }

    @Override
    public String getLink() {
        return link;
    }

    @Override
    public void setLink(String link) {
        this.link = link;
    }

    @Override
    @SuppressWarnings("unchecked")
    public List getComments() {
        return comments;
    }

    @Override
    @SuppressWarnings("unchecked")
    public void setComments(List comments) {
        this.comments = comments;
    }
}
